package com.iflytek.edu.db.core.utils;

import cn.hutool.core.util.StrUtil;
import com.alibaba.druid.DbType;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.iflytek.edu.db.core.constant.GrammarConstant;

/**
 * @author linkai
 * @date 2022/2/11
 */
public final class AstUtils {
    public static SQLExpr toSQLExpr(DbType dbType, String s) {
        return SQLUtils.toSQLExpr(s, dbType);
    }

    public static boolean checkQuote(String name) {
        return StrUtil.isNotBlank(name) && name.startsWith(GrammarConstant.BACKTICK);
    }

    public static String convertAlias(String alias) {
        return GrammarConstant.QUOTE + alias.substring(1, alias.length() - 1) + GrammarConstant.QUOTE;
    }

}
